package com.lagou.web.servlet;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.lang.reflect.Method;

@WebServlet("/test")
public class TestServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String methodName = req.getParameter("methodName");
//        if ("addCourse".equals(methodName)) {
//            addCourse(req, resp);
//        } else if ("findByName".equals(methodName)) {
//            findByName(req, resp);
//        } else if ("findByStatus".equals(methodName)) {
//            findByStatus(req, resp);
//        } else {
//            System.out.println("请求功能不存在！");
//        }
        if (null != methodName) {
            Class clazz = this.getClass();
            try {
                Method method = clazz.getMethod(methodName, HttpServletRequest.class, HttpServletResponse.class);
                method.invoke(this, req, resp);
            } catch (Exception e) {
                e.printStackTrace();
                System.out.println("请求功能不存在！");
            }
        }
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }

    public void addCourse(HttpServletRequest request, HttpServletResponse response) {

    }

    public void findByName(HttpServletRequest request, HttpServletResponse response) {

    }

    public void findByStatus(HttpServletRequest request, HttpServletResponse response) {

    }
}